
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Capitals</title>
<link rel="stylesheet" type="text/css" href="capitals_CSS.css" />

</head>
<body>
	<?php 
	phpinfo();
	define('EMPTY_SPACES', 4);
	
	if(isset($_POST['submit']))
	{
		$count = $_POST['hidden'];
		$count++;
	}
	else
	{
		$count = 1;
		$cap = "";
	}
	?>
	<?php
	if(!isset($_POST['submit']))
	{
		$buffer = "Press the button";
		$answer = 0;
	}
	else
	{
		
		
		$countries = array("","","Bulgaria?", "Portugal?", "Russia?", "Italy?", "Spain?", "Germany?", "USA?", "Czech Republic?", "France?", "England?");
		$capitals = array("","","Sofia", "Lisbon", "Moscow", "Rome", "Madrid", "Berlin", "Washington DC", "Prague", "Paris", "London");
		if($count < count($countries))
		{
			$cap = "";
			$buffer = $countries[$count];
			if($count == EMPTY_SPACES)
			{
				$cap = "";
				$answer = 0;
			}
			elseif(strcasecmp($_POST['input'], $capitals[$count - 1]) == 0  && $count != EMPTY_SPACES)
			{
				$answer = $_POST['guess'];
				$cap = "Right!";
				$answer++;
			}
			elseif(strcasecmp($_POST['input'], $capitals[$count - 1]) != 0 && $count != EMPTY_SPACES)
			{
				$answer = $_POST['guess'];
				$cap = "Wrong!";
			}
		}
		if($count == count($countries))
		{
			if(strcasecmp($_POST['input'], $capitals[$count - 1]) == 0)
			{
				$answer = $_POST['guess'];
				$cap = "Right!";
				$answer++;
				$buffer = "Press to see the result";
			}
			elseif(strcasecmp($_POST['input'], $capitals[$count - 1]) != 0)
			{
				$answer = $_POST['guess'];
				$cap = "Wrong!";
				$buffer = "Press to see the result";
			}
			$count = 0;
		}
		if($count > 12)
		{
			if($count == 13)
			{
				$buffer = "You answerd ".$_POST['guess']." / " + (count($countries)-EMPTY_SPACES) + "!";
				$cap = "";
				$count = 0;
			}
			else
			{
				$buffer = "Press to refresh";
				$cap = "";
			}
		}
	}
	?>
	<div id="main">
		<div id="title1">
			<pre id="title">Guess The 
Capital</pre>
			<p id="quest">What is the capital of....?</p>
			<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
				<input type="text" id="country" value="<?php echo ($buffer)?>"
					disabled /><br /> <input type="hidden"
					value="<?php echo ($count)?>" name="hidden" /><br /> <input
					name="input" id="input" type="text" placeholder="Your Answer..." />
				<input type="hidden" value="<?php echo @($answer)?>" name="guess" />
				<button name="submit" id="submit">Answer</button>

			</form>

		</div>
		<div id="result1">
			<input type="text" id="result" value="<?php echo @$cap;?>" disabled />
		</div>

	</div>
</body>
</html>
